package com.liangzai.springai.repository;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * 保存会话历史记录
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class InMemoryChatHistoryRepository implements ChatHistoryRepository {
    //map  存储会话历史记录
    private Map<String, List<String>> chatHistory  = new HashMap<>();;

    /**
     * 保存会话历史记录
     * @param type 业务类型，如：chat、service、pdf
     * @param chatId 会话ID
     */
    @Override
    public void save(String type, String chatId) {
        if (!chatHistory.containsKey(type)) {
            chatHistory.put(type, new ArrayList<>());
        }
        List<String> chatIds = chatHistory.get(type);
    }

    /**
     * 获取会话历史记录
     * @param type 业务类型，如：chat、service、pdf
     * @return
     */
    @Override
    public List<String> getChatIds(String type) {
        List<String> chatIds = chatHistory.get(type);
        return chatIds == null ? List.of() : chatIds;
        //return chatHistory.getOrDefault(type, List.of());
    }


}